package com.xjggb.demo.service;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;

@Service
public class HelloDTopicRabbitMQ {

    @Autowired
    private RabbitTemplate rabbitTemplate;


    public void hellorabbitmq(String id ,String prodid , int num){

//根据商品id查询数据库是否有库存
        String orderId = UUID.randomUUID().toString();
        System.out.println("订单生产成功 = " + orderId);

//        参数一  交换机 ，参数2路由key/queue队列名称，参数三消息内容

        //第一交换机
        String exchangeName="topic_order_exchange";
        String routingKey="com.email#";
        String outingKey="com.sms#";

        /*
        *email  和sms可以接收到信息
        * */
        rabbitTemplate.convertAndSend(exchangeName,routingKey,orderId);
        rabbitTemplate.convertAndSend(exchangeName,outingKey,orderId);

    }


}
